<?php

include_once 'structs.php';

$wsdl_url="http://127.0.0.1/workspace-php/soap/test.wsdl";
$options = array(
		'soap_version'=>SOAP_1_2,
		'exceptions'=>true,
		'trace'=>1,
		'login' => 'admin',
		'password' => 'admin',
		'cache_wsdl'=>WSDL_CACHE_NONE,
		'features'=>SOAP_SINGLE_ELEMENT_ARRAYS,
		'classmap' => array( 'Ops' => 'Params')
);

if(isset($_POST['azione'])){
	$client=new SoapClient($wsdl_url,$options);
	$azione = $_POST['azione'];
	//echo("azione:".$azione);
	try{
		switch ($azione){
			case "hello":
				if($_POST['name']!=null){
					print_r($client->sayHello(htmlentities($_POST['name'])));
				}
				break;
			case "somma":
				$a = $_POST['a'];
				$b = $_POST['b'];
				$q = new Params($a,$b);
				$r = $client->add($q);
				print_r($r);
				break;
			case "moltiplicazione":
				$a = $_POST['a'];
				$b = $_POST['b'];
				$q = new Params($a,$b);
				$r = $client->mult($q);
				print_r($r);
				break;
		}
	}catch (SoapFault $fault) {
		print("ERROR:".$fault);
		trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
	}
}
?>
